/**
 * SEVAS - Swiss Electronic Vaccination Advisor Service / Agile Development
 *
 * $Id: Application.java 29 2010-08-18 16:51:14Z zimmr7@bfh.ch $
 */
package ch.bfh.sevas.gui;

import ch.bfh.sevas.BaseVaccinationCatalog;
import ch.bfh.sevas.Controller;
import ch.bfh.sevas.DateConverter;
import ch.bfh.sevas.Initializer;
import ch.bfh.sevas.Patient;
import ch.bfh.sevas.RecommendedBaseVaccination;
import ch.bfh.sevas.Vaccination;
import ch.bfh.sevas.VaccinationScheduleEntry;
import ch.bfh.sevas.VaccinationsScheduleModel;
import ch.bfh.sevas.exceptions.NonexistentEntityException;
import java.awt.CardLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;

public class VaccinationCardView extends FrameView {

    private BaseVaccinationCatalog catalog;
    private SingleFrameApplication application;
    private DateConverter dateConverter;
    public List<Patient> patients;
    private Controller controller;
    private Patient patient;

    public VaccinationCardView(SingleFrameApplication application, Controller controller) throws Exception {
        super(application);

        this.dateConverter = new DateConverter();
        this.controller = controller;

        Long id = Initializer.initSEVAS();
        patient = controller.findPatientById(id);
        patients = new ArrayList<Patient>();

        initComponents();
    }

    public List<Patient> getPatients() {
        return patients;
    }

    public void setPatients(List<Patient> patients) {
        this.patients = patients;
    }

    public DateConverter getDateConverter() {
        return dateConverter;
    }

    public void setDateConverter(DateConverter dateConverter) {
        this.dateConverter = dateConverter;
    }

    public Patient getPatient() {
        return patient;
    }

    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    @Action
    public void deleteVacination() throws NonexistentEntityException, Exception {
        Object item = null;

        int[] selected = tblVacc.getSelectedRows();
        for (int i = 0; i < selected.length; i++) {
            item = patient.getVaccinations().get(tblVacc.convertRowIndexToModel(selected[i]));
        }

        bindingGroup.unbind();
        patient.removeVaccination((Vaccination) item);
        bindingGroup.bind();
    }

    @Action
    public void saveAll() {
        try {
            controller.edit(patient);
        } catch (Exception ex) {
            Logger.getLogger(VaccinationCardView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ElectronicVaccinationCard.getApplication().getMainFrame();
            aboutBox = new VaccinationCardAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ElectronicVaccinationCard.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        groupSex = new javax.swing.ButtonGroup();
        panelMain = new javax.swing.JPanel();
        panelTitle = new javax.swing.JPanel();
        javax.swing.JLabel appTitleLabel = new javax.swing.JLabel();
        javax.swing.JLabel appDescLabel = new javax.swing.JLabel();
        javax.swing.JLabel imageLabel = new javax.swing.JLabel();
        userLabel = new javax.swing.JLabel();
        userLabel1 = new javax.swing.JLabel();
        dateLabel1 = new javax.swing.JLabel();
        dateLabel = new javax.swing.JLabel();
        panelContent = new javax.swing.JPanel();
        panelSearch = new javax.swing.JPanel();
        btnShowDetail = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtGivenName = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtSurname = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtSSN = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        txtDateOfBirth = new javax.swing.JFormattedTextField();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPatients = new javax.swing.JTable();
        jButton9 = new javax.swing.JButton();
        btnNewPatient = new javax.swing.JButton();
        panelDetail = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        sexLabel = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblVacc = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblSchedule = new javax.swing.JTable();
        tblSchedule.setDefaultRenderer(Object.class, new ColorRenderer());
        ch.bfh.sevas.gui.VaccinationScheduleToolTipHeader header = new ch.bfh.sevas.gui.VaccinationScheduleToolTipHeader(tblSchedule.getColumnModel());
        tblSchedule.setTableHeader(header);

        panelMain.setName("panelMain"); // NOI18N
        panelMain.setLayout(new java.awt.BorderLayout());

        panelTitle.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
        panelTitle.setName("panelTitle"); // NOI18N
        panelTitle.setNextFocusableComponent(panelContent);

        appTitleLabel.setFont(appTitleLabel.getFont().deriveFont(appTitleLabel.getFont().getStyle() | java.awt.Font.BOLD, appTitleLabel.getFont().getSize()+11));
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ch.bfh.sevas.gui.ElectronicVaccinationCard.class).getContext().getResourceMap(VaccinationCardView.class);
        appTitleLabel.setForeground(resourceMap.getColor("appTitleLabel.foreground")); // NOI18N
        appTitleLabel.setText(resourceMap.getString("appTitleLabel.text")); // NOI18N
        appTitleLabel.setName("appTitleLabel"); // NOI18N

        appDescLabel.setFont(resourceMap.getFont("appDescLabel.font")); // NOI18N
        appDescLabel.setForeground(resourceMap.getColor("appDescLabel.foreground")); // NOI18N
        appDescLabel.setText(resourceMap.getString("appDescLabel.text")); // NOI18N
        appDescLabel.setName("appDescLabel"); // NOI18N

        imageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        imageLabel.setIcon(resourceMap.getIcon("imageLabel.icon")); // NOI18N
        imageLabel.setAlignmentY(0.0F);
        imageLabel.setBorder(javax.swing.BorderFactory.createLineBorder(resourceMap.getColor("imageLabel.border.lineColor"))); // NOI18N
        imageLabel.setFocusable(false);
        imageLabel.setName("imageLabel"); // NOI18N

        userLabel.setForeground(resourceMap.getColor("userLabel.foreground")); // NOI18N
        userLabel.setText(controller.getUser().getSignature());
        userLabel.setName("userLabel"); // NOI18N

        userLabel1.setForeground(resourceMap.getColor("userLabel1.foreground")); // NOI18N
        userLabel1.setText(resourceMap.getString("userLabel1.text")); // NOI18N
        userLabel1.setName("userLabel1"); // NOI18N

        dateLabel1.setForeground(resourceMap.getColor("dateLabel1.foreground")); // NOI18N
        dateLabel1.setText(resourceMap.getString("dateLabel1.text")); // NOI18N
        dateLabel1.setName("dateLabel1"); // NOI18N

        dateLabel.setText(new DateConverter().convertForward(new Date()));
        dateLabel.setName("dateLabel"); // NOI18N

        javax.swing.GroupLayout panelTitleLayout = new javax.swing.GroupLayout(panelTitle);
        panelTitle.setLayout(panelTitleLayout);
        panelTitleLayout.setHorizontalGroup(
            panelTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTitleLayout.createSequentialGroup()
                .addGroup(panelTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(appTitleLabel)
                    .addGroup(panelTitleLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(appDescLabel))
                    .addGroup(panelTitleLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(dateLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dateLabel)
                        .addGap(18, 18, 18)
                        .addComponent(userLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(userLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                .addComponent(imageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        panelTitleLayout.setVerticalGroup(
            panelTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTitleLayout.createSequentialGroup()
                .addGroup(panelTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelTitleLayout.createSequentialGroup()
                        .addComponent(appTitleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(appDescLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(dateLabel1)
                            .addComponent(dateLabel)
                            .addComponent(userLabel)
                            .addComponent(userLabel1)))
                    .addComponent(imageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        userLabel.getAccessibleContext().setAccessibleName(resourceMap.getString("userLabel.AccessibleContext.accessibleName")); // NOI18N
        dateLabel.getAccessibleContext().setAccessibleName(resourceMap.getString("dateLabel.AccessibleContext.accessibleName")); // NOI18N

        panelMain.add(panelTitle, java.awt.BorderLayout.CENTER);

        panelContent.setName("panelContent"); // NOI18N
        panelContent.setLayout(new java.awt.CardLayout());

        panelSearch.setForeground(resourceMap.getColor("panelSearch.foreground")); // NOI18N
        panelSearch.setName("panelSearch"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(ch.bfh.sevas.gui.ElectronicVaccinationCard.class).getContext().getActionMap(VaccinationCardView.class, this);
        btnShowDetail.setAction(actionMap.get("showDetail")); // NOI18N
        btnShowDetail.setForeground(resourceMap.getColor("btnShowDetail.foreground")); // NOI18N
        btnShowDetail.setText(resourceMap.getString("btnShowDetail.text")); // NOI18N
        btnShowDetail.setToolTipText(resourceMap.getString("btnShowDetail.toolTipText")); // NOI18N
        btnShowDetail.setName("btnShowDetail"); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel5.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel5.border.titleColor"))); // NOI18N
        jPanel5.setForeground(resourceMap.getColor("jPanel5.foreground")); // NOI18N
        jPanel5.setName("jPanel5"); // NOI18N
        jPanel5.setLayout(new java.awt.GridLayout(1, 0));

        jPanel7.setName("jPanel7"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        txtGivenName.setFont(resourceMap.getFont("txtGivenName.font")); // NOI18N
        txtGivenName.setMinimumSize(new java.awt.Dimension(80, 20));
        txtGivenName.setName("txtGivenName"); // NOI18N
        txtGivenName.setPreferredSize(new java.awt.Dimension(80, 20));

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${searchCriteria.givenName}"), txtGivenName, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        txtSurname.setFont(resourceMap.getFont("txtSurname.font")); // NOI18N
        txtSurname.setMinimumSize(new java.awt.Dimension(80, 20));
        txtSurname.setName("txtSurname"); // NOI18N
        txtSurname.setPreferredSize(new java.awt.Dimension(80, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${searchCriteria.surname}"), txtSurname, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtSurname, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                    .addComponent(txtGivenName, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtGivenName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel5.add(jPanel7);

        jPanel8.setName("jPanel8"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        txtSSN.setFont(resourceMap.getFont("txtSSN.font")); // NOI18N
        txtSSN.setMinimumSize(new java.awt.Dimension(80, 20));
        txtSSN.setName("txtSSN"); // NOI18N
        txtSSN.setPreferredSize(new java.awt.Dimension(80, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${searchCriteria.ssn}"), txtSSN, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jButton7.setAction(actionMap.get("searchPatients")); // NOI18N
        jButton7.setForeground(resourceMap.getColor("jButton7.foreground")); // NOI18N
        jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N

        txtDateOfBirth.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
        txtDateOfBirth.setName("txtDateOfBirth"); // NOI18N

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtSSN, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                        .addComponent(txtDateOfBirth, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7)))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSSN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jButton7)
                    .addComponent(txtDateOfBirth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jPanel5.add(jPanel8);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel6.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel6.border.titleColor"))); // NOI18N
        jPanel6.setName("jPanel6"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblPatients.setColumnSelectionAllowed(true);
        tblPatients.setName("tblPatients"); // NOI18N
        tblPatients.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblPatients.getTableHeader().setReorderingAllowed(false);

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${patients}");
        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, tblPatients);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${givenName}"));
        columnBinding.setColumnName("Given Name");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${surname}"));
        columnBinding.setColumnName("Surname");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${sexAsString}"));
        columnBinding.setColumnName("Sex As String");
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dateOfBirth}"));
        columnBinding.setColumnName("Date Of Birth");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${ssn}"));
        columnBinding.setColumnName("Ssn");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(tblPatients);
        tblPatients.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblPatients.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tblPatients.columnModel.title0")); // NOI18N
        tblPatients.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tblPatients.columnModel.title1")); // NOI18N
        tblPatients.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tblPatients.columnModel.title2")); // NOI18N
        tblPatients.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("tblPatients.columnModel.title3")); // NOI18N
        tblPatients.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("tblPatients.columnModel.title4")); // NOI18N

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 689, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButton9.setAction(actionMap.get("quit")); // NOI18N
        jButton9.setForeground(resourceMap.getColor("jButton9.foreground")); // NOI18N
        jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
        jButton9.setName("jButton9"); // NOI18N

        btnNewPatient.setAction(actionMap.get("createPatient")); // NOI18N
        btnNewPatient.setForeground(resourceMap.getColor("btnNewPatient.foreground")); // NOI18N
        btnNewPatient.setText(resourceMap.getString("btnNewPatient.text")); // NOI18N
        btnNewPatient.setToolTipText(resourceMap.getString("btnNewPatient.toolTipText")); // NOI18N
        btnNewPatient.setName("btnNewPatient"); // NOI18N

        javax.swing.GroupLayout panelSearchLayout = new javax.swing.GroupLayout(panelSearch);
        panelSearch.setLayout(panelSearchLayout);
        panelSearchLayout.setHorizontalGroup(
            panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 721, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSearchLayout.createSequentialGroup()
                        .addComponent(btnNewPatient)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnShowDetail)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton9)))
                .addContainerGap())
        );
        panelSearchLayout.setVerticalGroup(
            panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelSearchLayout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton9)
                    .addComponent(btnShowDetail)
                    .addComponent(btnNewPatient))
                .addContainerGap())
        );

        panelContent.add(panelSearch, "cardSearch");

        panelDetail.setMaximumSize(new java.awt.Dimension(640, 480));
        panelDetail.setMinimumSize(new java.awt.Dimension(640, 480));
        panelDetail.setName("panelDetail"); // NOI18N
        panelDetail.setPreferredSize(new java.awt.Dimension(640, 480));

        jPanel3.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel2.border.titleColor"))); // NOI18N
        jPanel3.setForeground(resourceMap.getColor("jPanel2.foreground")); // NOI18N
        jPanel3.setName("jPanel2"); // NOI18N
        jPanel3.setLayout(new java.awt.GridLayout(1, 0));

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextField3.setBackground(resourceMap.getColor("jTextField4.background")); // NOI18N
        jTextField3.setFont(resourceMap.getFont("jTextField3.font")); // NOI18N
        jTextField3.setMinimumSize(new java.awt.Dimension(80, 20));
        jTextField3.setName("jTextField3"); // NOI18N
        jTextField3.setPreferredSize(new java.awt.Dimension(80, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${patient.givenName}"), jTextField3, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jTextField4.setBackground(resourceMap.getColor("jTextField4.background")); // NOI18N
        jTextField4.setFont(resourceMap.getFont("jTextField4.font")); // NOI18N
        jTextField4.setMinimumSize(new java.awt.Dimension(80, 20));
        jTextField4.setName("jTextField4"); // NOI18N
        jTextField4.setPreferredSize(new java.awt.Dimension(80, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${patient.surname}"), jTextField4, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel3.add(jPanel1);

        jPanel4.setName("jPanel4"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jTextField5.setBackground(resourceMap.getColor("jTextField4.background")); // NOI18N
        jTextField5.setFont(resourceMap.getFont("jTextField5.font")); // NOI18N
        jTextField5.setMinimumSize(new java.awt.Dimension(80, 20));
        jTextField5.setName("jTextField5"); // NOI18N
        jTextField5.setPreferredSize(new java.awt.Dimension(80, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${patient.ssn}"), jTextField5, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jTextField6.setBackground(resourceMap.getColor("jTextField4.background")); // NOI18N
        jTextField6.setFont(resourceMap.getFont("jTextField6.font")); // NOI18N
        jTextField6.setMaximumSize(new java.awt.Dimension(68, 20));
        jTextField6.setMinimumSize(new java.awt.Dimension(68, 20));
        jTextField6.setName("jTextField6"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${patient.dateOfBirth}"), jTextField6, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setConverter(dateConverter);
        bindingGroup.addBinding(binding);

        sexLabel.setText("Sex:"); // NOI18N
        sexLabel.setName("sexLabel"); // NOI18N

        groupSex.add(jRadioButton1);
        jRadioButton1.setText(resourceMap.getString("jRadioButton1.text")); // NOI18N
        jRadioButton1.setName("jRadioButton1"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${patient.male}"), jRadioButton1, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        groupSex.add(jRadioButton2);
        jRadioButton2.setText(resourceMap.getString("jRadioButton2.text")); // NOI18N
        jRadioButton2.setName("jRadioButton2"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${patient.female}"), jRadioButton2, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(sexLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton2))
                    .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton1)
                    .addComponent(sexLabel))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jPanel3.add(jPanel4);

        jButton5.setAction(actionMap.get("quit")); // NOI18N
        jButton5.setFont(resourceMap.getFont("jButton5.font")); // NOI18N
        jButton5.setForeground(resourceMap.getColor("jButton5.foreground")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N

        jButton6.setAction(actionMap.get("showAboutBox")); // NOI18N
        jButton6.setForeground(resourceMap.getColor("jButton6.foreground")); // NOI18N
        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        jButton3.setAction(actionMap.get("saveAll")); // NOI18N
        jButton3.setForeground(resourceMap.getColor("jButton3.foreground")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setToolTipText(resourceMap.getString("jButton3.toolTipText")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jButton4.setAction(actionMap.get("showSearch")); // NOI18N
        jButton4.setForeground(resourceMap.getColor("jButton4.foreground")); // NOI18N
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setToolTipText(resourceMap.getString("jButton4.toolTipText")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel2.setName("jPanel3"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tblVacc.setForeground(resourceMap.getColor("tblVaccinations.foreground")); // NOI18N
        tblVacc.setToolTipText(resourceMap.getString("tblVaccinations.toolTipText")); // NOI18N
        tblVacc.setColumnSelectionAllowed(true);
        tblVacc.setFocusTraversalPolicyProvider(true);
        tblVacc.setName("tblVaccinations"); // NOI18N
        tblVacc.setRowHeight(17);
        tblVacc.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${patient.vaccinations}");
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, tblVacc);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${antigen}"));
        columnBinding.setColumnName("Antigen");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vaccine}"));
        columnBinding.setColumnName("Vaccine");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${manufacturer}"));
        columnBinding.setColumnName("Manufacturer");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${batchNo}"));
        columnBinding.setColumnName("Batch No");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${done}"));
        columnBinding.setColumnName("Done");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dose}"));
        columnBinding.setColumnName("Dose");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${physician}"));
        columnBinding.setColumnName("Physician");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${note}"));
        columnBinding.setColumnName("Note");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane2.setViewportView(tblVacc);
        tblVacc.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        tblVacc.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title0")); // NOI18N
        tblVacc.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title1")); // NOI18N
        tblVacc.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title2")); // NOI18N
        tblVacc.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title3")); // NOI18N
        tblVacc.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title4")); // NOI18N
        tblVacc.getColumnModel().getColumn(4).setCellRenderer(new DateRenderer());
        tblVacc.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title5")); // NOI18N
        tblVacc.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title6")); // NOI18N
        tblVacc.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("tblVaccinations.columnModel.title7")); // NOI18N
        tblVacc.getColumnModel().getColumn(7).setCellRenderer(new TooltipRenderer());

        jButton1.setAction(actionMap.get("deleteVacination")); // NOI18N
        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("jButton1.toolTipText")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
                    .addComponent(jButton1))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jPanel9.setName("jPanel9"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        tblSchedule.setModel(new ch.bfh.sevas.VaccinationsScheduleModel(patient, controller));
        tblSchedule.setName("tblSchedule"); // NOI18N
        tblSchedule.getTableHeader().setReorderingAllowed(false);
        tblSchedule.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblScheduleMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tblSchedule);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel9.TabConstraints.tabTitle"), jPanel9); // NOI18N

        javax.swing.GroupLayout panelDetailLayout = new javax.swing.GroupLayout(panelDetail);
        panelDetail.setLayout(panelDetailLayout);
        panelDetailLayout.setHorizontalGroup(
            panelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelDetailLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 721, Short.MAX_VALUE)
                    .addGroup(panelDetailLayout.createSequentialGroup()
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 721, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelDetailLayout.setVerticalGroup(
            panelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDetailLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(panelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton6)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap())
        );

        jPanel3.getAccessibleContext().setAccessibleName(resourceMap.getString("jPanel2.AccessibleContext.accessibleName")); // NOI18N

        panelContent.add(panelDetail, "cardDetail");

        panelMain.add(panelContent, java.awt.BorderLayout.SOUTH);

        setComponent(panelMain);

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    class MenuActionListener implements ActionListener {
        private Frame parentFrame;
        private VaccinationScheduleEntry calendarEntry;

        private MenuActionListener(Frame parent, VaccinationScheduleEntry entry) {
            this.parentFrame = parent;
            this.calendarEntry = entry;
        }
        
        public void actionPerformed(ActionEvent evt) {

            if (tblSchedule.getSelectedRowCount() == 1 && tblSchedule.getSelectedColumnCount() == 1) {

                int row = tblSchedule.getSelectedRows()[0];
                int column = tblSchedule.getSelectedColumns()[0];
                if (column == 0) return;    //column[0] = Age

                AdministerVaccincationDialog dialog = new AdministerVaccincationDialog(calendarEntry, parentFrame, true);
                dialog.setVisible(true); if (dialog.getReturnStatus() == AdministerVaccincationDialog.RET_CANCEL) return;

                if (catalog == null) {
                    catalog = BaseVaccinationCatalog.getFilledBaseVaccineCatalog();
                }

                VaccinationScheduleEntry entry = (VaccinationScheduleEntry) tblSchedule.getModel().getValueAt(row, column);
                RecommendedBaseVaccination recommendation = entry.getBaseVaccination();
                String age = entry.getVaccinationAge();

                bindingGroup.unbind();
                controller.addVaccinationFromTemplate(patient, recommendation, dialog.getBatchNo(), dialog.getNote(), dialog.getDose(), age);
                bindingGroup.bind();
            }
        }
    }

    private void tblScheduleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblScheduleMouseClicked
        if (SwingUtilities.isRightMouseButton(evt)) {

            int viewRow = tblSchedule.rowAtPoint(evt.getPoint());
            int row = tblSchedule.convertRowIndexToModel(viewRow);
            int viewColumn = tblSchedule.columnAtPoint(evt.getPoint());
            int column = tblSchedule.convertColumnIndexToModel(viewColumn);

            Object value = tblSchedule.getModel().getValueAt(row, column);
            if (value instanceof VaccinationScheduleEntry) {
                VaccinationScheduleEntry entry = (VaccinationScheduleEntry) value;

                if (!entry.toString().equals("DONE")) {
                    JPopupMenu popupMenu = new JPopupMenu();
                    JMenuItem item = new JMenuItem("Administer vaccination");
                    item.addActionListener(new MenuActionListener(ElectronicVaccinationCard.getApplication().getMainFrame(), entry));
                    popupMenu.add(item);
                    popupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
                }
            }
            
        }
    }//GEN-LAST:event_tblScheduleMouseClicked

    @Action
    public void showSearch() {
        
        bindingGroup.unbind();
        patients.clear();
        bindingGroup.bind();

        CardLayout layout = (CardLayout)(panelContent.getLayout());
        layout.show(panelContent, "cardSearch");
    }

    @Action
    public void showDetail() {
        if (tblPatients.getSelectedRows().length == 1) {
            int selected = tblPatients.getSelectedRows()[0];

            bindingGroup.unbind();
            patient = patients.get(tblPatients.convertRowIndexToModel(selected));
            bindingGroup.bind();

            CardLayout layout = (CardLayout)(panelContent.getLayout());
            tblSchedule.setModel(new VaccinationsScheduleModel(patient, controller));
            layout.show(panelContent, "cardDetail");
        }
    }

    @Action
    public void searchPatients() {

        Map<String,String> attr = new HashMap<String,String>();

        if (!txtGivenName.getText().isEmpty()) attr.put("givenName", txtGivenName.getText());
        if (!txtSurname.getText().isEmpty()) attr.put("surname", txtSurname.getText());
        if (!txtDateOfBirth.getText().isEmpty()) attr.put("dateOfBirth", txtDateOfBirth.getText());
        if (!txtSSN.getText().isEmpty()) attr.put("ssn", txtSSN.getText());

        bindingGroup.unbind();
        patients = controller.findPatientsByAttributes(attr);
        bindingGroup.bind();
    }

    @Action
    public void createPatient() {
        bindingGroup.unbind();
        patient = new Patient("", "<New Patient>", null, 0, "");
        controller.create(patient); bindingGroup.bind();

        CardLayout layout = (CardLayout)(panelContent.getLayout());
        tblSchedule.setModel(new VaccinationsScheduleModel(patient, controller));
        layout.show(panelContent, "cardDetail");txtGivenName.selectAll();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNewPatient;
    private javax.swing.JButton btnShowDetail;
    private javax.swing.JLabel dateLabel;
    private javax.swing.JLabel dateLabel1;
    private javax.swing.ButtonGroup groupSex;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JPanel panelContent;
    private javax.swing.JPanel panelDetail;
    private javax.swing.JPanel panelMain;
    private javax.swing.JPanel panelSearch;
    private javax.swing.JPanel panelTitle;
    private javax.swing.JLabel sexLabel;
    private javax.swing.JTable tblPatients;
    private javax.swing.JTable tblSchedule;
    private javax.swing.JTable tblVacc;
    private javax.swing.JFormattedTextField txtDateOfBirth;
    private javax.swing.JTextField txtGivenName;
    private javax.swing.JTextField txtSSN;
    private javax.swing.JTextField txtSurname;
    private javax.swing.JLabel userLabel;
    private javax.swing.JLabel userLabel1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private JDialog aboutBox;
}
